package com.face.mapper;

import com.face.entity.Visit;
import org.apache.ibatis.annotations.*;

import com.face.entity.Shop;

@Mapper
public interface ShopMapper {


    @Select("select * from tb_shop where shopId = #{shopId} and deviceId = #{deviceId}")
    Shop getShop(@Param("shopId") String shopId, @Param("deviceId") String deviceId);

    @Insert("insert into tb_visit(id,shopId,userId,username,loginTime) values(#{id},#{shopId},#{userId},#{username},#{loginTime})")
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id", before = false, resultType = Integer.class)
    Integer saveVisit(Visit visit);

    @Insert("insert into tb_shop (shopId, deviceId, address, manager, telephone, createTime, startTime, endTime, shopName, province, city, region, corporation, idCard, updateTime) values(#{shopId}, #{deviceId}, #{address}, #{manager}, #{telephone}, #{createTime}, #{startTime}, #{endTime}, #{shopName}, #{province}, #{city}, #{region}, #{corporation}, #{idCard}, #{updateTime})")
    void save(Shop shop);

    @Select("select * from tb_shop where shopId = #{shopId}")
    Shop findByShopId(String shopId);

    @Update("update tb_shop set address = #{address}, province = #{province}, city = #{city}, region = #{region}, shopName = #{shopName}, corporation = #{corporation}, " +
            "telephone = #{telephone}, contact = #{contact}, idCard = #{idCard}, updateTime=#{updateTime} where shopId = #{shopId}")
    void update(Shop shop);

    @Select("select a.* from tb_shop a left join tb_account b on a.shopId = b.shopId where b.activeCode = #{activeCode}")
    Shop findShopByActiveCode(String activeCode);
}
